﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    
    public partial class ArtikelsucheEinfach : Form
    {

        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;

        public Guid artikel;
        
        public ArtikelsucheEinfach()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();

        }

        private void ArtikelsucheEinfach_Load(object sender, EventArgs e)
        {
            LoadData();

            txShowArtikelNr.DataBindings.Add(new Binding("Text", bindingSource, "Artikel_Nr"));
            txShowBezeichnung.DataBindings.Add(new Binding("Text", bindingSource, "Name"));
            txShowID.DataBindings.Add(new Binding("Text", bindingSource, "ID"));
        }


        protected void LoadData()
        {
            IQueryable<Product_Main> dataQuery = (from a in diveDatabase.Product_Main
                                                   select a);

            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;

            // Bind BindingSource to List
            ArtikelList.DataSource = bindingSource;


            // Hide ID-Columns
            ArtikelList.Columns["ID"].Visible = false;
            ArtikelList.Columns["Artikel_Nr"].Visible = true;
            ArtikelList.Columns["Name"].Visible = true;


            // Set Column Headers
            ArtikelList.Columns["Artikel_Nr"].HeaderText = "Art. Nr";
            ArtikelList.Columns["Name"].HeaderText = "Bezeichnung";


        }

        private void btOK_Click(object sender, EventArgs e)
        {
            //Abschließen der Artikelsuche

            artikel = new Guid(txShowID.Text);

            Close();
        }
    }
}
